package my.suveng.nettyhello.module.server;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * create at 2018/10/20
 * author: suveng
 * email: suveng@163.com
 * 这是一个初始化器，channel 注册后会执行相应的初始化方法
 **/
public class HelloServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
//        获取socket channel 获取对应的管道pipeline
        ChannelPipeline pipeline = socketChannel.pipeline();
//        为管道添加handler 处理器,HttpServerCodec 是netty提供的助手处理器，用来处理http协议的编码和解码。
        pipeline.addLast("http",new HttpServerCodec());
//        添加自定义的处理器;返回hello netty 字符串
        pipeline.addLast("custom",new CustomHandler());

    }
}
